package com.bc.bczbweb.controller.Ajax;

import com.bc.commonentity.common.JsonResult;
import com.bc.bcapi.service.T_Mng_email_confService;
import com.bc.bcmodel.domain.T_Mng_email_confModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.POST;
import java.math.BigInteger;

@RestController
@RequestMapping("ajax/t_mng_email_conf")
public class AjaxT_Mng_email_confController {
    @Autowired
    T_Mng_email_confService t_Mng_email_confService;

    @POST
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public JsonResult add(T_Mng_email_confModel req) {
        JsonResult js = new JsonResult();
        if (req.getId() != null && req.getId().intValue() > 0) {
            t_Mng_email_confService.update(req);
        } else {
            t_Mng_email_confService.insert(req);
        }
        return js;
    }

    @RequestMapping("del")
    public JsonResult del(BigInteger id) {
        JsonResult js = new JsonResult();
        T_Mng_email_confModel t_mng_email_confModelparam = new T_Mng_email_confModel();
        t_mng_email_confModelparam.setId(id);
        T_Mng_email_confModel t_mng_email_confModel = t_Mng_email_confService.findByNamedParam(t_mng_email_confModelparam);
        if (t_mng_email_confModel == null) {
            return js;
        }
        int status = t_mng_email_confModel.getStatus() == 1 ? 2 : 1;
        t_mng_email_confModel.setStatus(status);
        t_Mng_email_confService.update(t_mng_email_confModel);
        return js;
    }
}